package com.yzy.models
{
	import flash.display.BitmapData;
	import flash.media.Sound;
	import flash.utils.ByteArray;
	import flash.utils.Dictionary;

	public class SetLibs
	{
		public function SetLibs(){}
		
		private static var LibsDatas:Vector.<Dictionary>=new Vector.<Dictionary>();
		/**
		 * 
		 * @param fileName
		 * @param data
		 * @param newGroup
		 * @param groupNo
		 * var groupEnum:object={Left:0,ight:1,up:2,down:3};
		 * var groupNum:Number=directions.Left;
		 */		
		public static function setLibsData(fileName:String,data:ByteArray,newGroup:Boolean=false,groupNo:uint=0):void{
			if(!LibsDatas.length){LibsDatas.push(new Dictionary())};
			var currGroup:Dictionary;
			if(newGroup){
				currGroup=new Dictionary();
				LibsDatas.push(currGroup);
			}else{
				currGroup=LibsDatas[groupNo];
			}
			
			currGroup[fileName]=data;
			currGroup[fileName].compress();
		}
		
		/**
		 * 
		 * @param fileName
		 * @param group
		 * @return 
		 * 
		 */		
		public static function getLibsData(fileName:String,group:uint=0):ByteArray{
			try{
				var ba:ByteArray=LibsDatas[group][fileName];
				ba.uncompress();
			}catch(e:Error){
				trace(fileName);
			}
			return ba;
		}
		/**
		 * 
		 * @param fileName
		 * @param group
		 * 
		 */		
		public static function removeData(fileName:String,group:uint=0):void{
			LibsDatas[group][fileName]=null;
		}
		/**
		 * 
		 * @param group
		 * 
		 */		
		public static function removeGroup(group:uint):void{
			LibsDatas.splice(group,1);
		}
		/**
		 * 
		 * 
		 */		
		public static function removeLibs():void{
			LibsDatas=null;
			LibsDatas=new Vector.<Dictionary>();
		}
		
		//*****************************************************
		//
		//*****************************************************
		public static var _BitmapDs:Dictionary=new Dictionary();
		public static function getBitmapData(fileName:String):BitmapData
		{
			return _BitmapDs[fileName];
		}
		
		public static function setBitmapData(fileName:String,data:BitmapData):void
		{
			_BitmapDs[fileName]=data;
		}
		
		//*********************
		public static var _SoundDs:Dictionary=new Dictionary();
		public static function getSoundDs(fileName:String):Sound
		{
			return _SoundDs[fileName];
		}
		
		public static function setSoundDs(fileName:String,sound:Sound):void
		{
			_SoundDs[fileName]=sound;
		}
		
		//*********************
		public static var _MovieClipDs:Dictionary=new Dictionary();
		public static function getMovieClipDs(fileName:String):Class
		{
			return _MovieClipDs[fileName];
		}
		
		public static function setMovieClipDs(fileName:String,cls:Class):void
		{
			_MovieClipDs[fileName]=cls;
		}
		
		
		//-------------------------
		//
		//-------------------------
		public static function removeElement(dic:Dictionary,delName:String):void{
			if(dic == _BitmapDs){
				_BitmapDs[delName].dispose();	
			}
			dic[delName]=null;
			delete dic[delName];
		}
		public static function removeAllElement(dic:Dictionary):void{
			dic=new Dictionary();
		}
	}
}